﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExtendBLL
{
    public class Privilege
    {
        static public List<LabMS.Model.Function> GetManaFunctionByUserID(string strUserID)
        {
            List<LabMS.Model.UserRole> listuRole = new List<LabMS.Model.UserRole>();
            LabMS.BLL.UserRole buRole = new LabMS.BLL.UserRole();
            List<LabMS.Model.RoleFucntion> listRoleF = new List<LabMS.Model.RoleFucntion>();
            LabMS.BLL.RoleFucntion bRoleF = new LabMS.BLL.RoleFucntion();

            listuRole = buRole.GetModelList("UserID = " + strUserID);

            string strWhere = " 1<>1 ";

            foreach (LabMS.Model.UserRole ur in listuRole)
            {
                strWhere += " or RoleID = " + ur.RoleID.Value.ToString();
            }
            listRoleF = bRoleF.GetModelList(strWhere);

            List<LabMS.Model.Function> listFunction = new List<LabMS.Model.Function>();
            LabMS.BLL.Function bFunction = new LabMS.BLL.Function();
            strWhere = " 1<>1 ";

            foreach (LabMS.Model.RoleFucntion rf in listRoleF)
            {
                strWhere += " or Code = '" + rf.FCode.ToString()+"'";
            }
            listFunction = bFunction.GetModelList(strWhere);
            return listFunction;            
        }

        static public List<LabMS.Model.Module> GetManaModuleByUserID(string strUserID)
        {
            List<LabMS.Model.Function> listFunction = new List<LabMS.Model.Function>();
            listFunction = GetManaFunctionByUserID(strUserID);

            List<LabMS.Model.Module> listModule = new List<LabMS.Model.Module>();
            LabMS.BLL.Module bModule = new LabMS.BLL.Module();
            string strWhere = " 1<>1 ";

            foreach (LabMS.Model.Function f in listFunction)
            {
                strWhere += " or Code = '" + f.MCode.ToString()+"'";
            }
            listModule = bModule.GetModelList(strWhere);

            return listModule;
        }

        static public List<LabMS.Model.Plate> GetManaPlateByUserID(string strUserID)
        {
            List<LabMS.Model.Module> listModule = GetManaModuleByUserID(strUserID); ;
            LabMS.BLL.Plate bPlate = new LabMS.BLL.Plate();
            List<LabMS.Model.Plate> listPlate = new List<LabMS.Model.Plate>();
            string strWhere = " 1<>1 ";
             foreach (LabMS.Model.Module m in listModule)
            {
                strWhere += " or Code = '" + m.PCode.ToString()+"'";
            }
            listPlate = bPlate.GetModelList(strWhere);

            return listPlate;
        }
    }
}
